package com.socialrss.accounts.factoryobject;

import android.content.ContentValues;
import android.database.Cursor;

import com.socialrss.accounts.AbstractHolder;
import com.socialrss.accounts.FollowedPerson;
import com.socialrss.accounts.dbinterfaces.ConnectionTable;
import com.socialrss.constants.SocialNetworkNames.SocialNetKeys;

public class ConnectionFactory extends AbstractHolderFactory {

	@Override
	public AbstractHolder turnToObj(Cursor cur) {
		FollowedPerson temp  = new FollowedPerson(cur.getInt(0), cur.getString(1), SocialNetKeys.valueOf(cur.getString(2)), cur.getInt(3), cur.getString(4));
		return temp;
	}
	/**
	 * Used for inserting new connection into database
	 */
	@Override
	public ContentValues tunToDBInput(AbstractHolder abs) {
		ContentValues values = new ContentValues();
		values.put(ConnectionTable.NAME, ((FollowedPerson)abs).getName());
		values.put(ConnectionTable.SOCIAL_AREA, ((FollowedPerson)abs).getConntype().toString());
		values.put(ConnectionTable.SELECTED, ((FollowedPerson)abs).isTurnedOn());
		values.put(ConnectionTable.USERID, ((FollowedPerson)abs).getUserid());
		return values;
	}
	/**
	 * Used for updating a connection in database
	 */
	@Override
	public ContentValues turnToPartialDBInput(AbstractHolder abs, String...columns){
		ContentValues values = new ContentValues();
		for (int i = 0; i < columns.length; i++) {
			if(columns[i].equals(ConnectionTable.NAME))
				values.put(ConnectionTable.NAME, ((FollowedPerson)abs).getName());
			else if(columns[i].equals(ConnectionTable.SOCIAL_AREA))
				values.put(ConnectionTable.SOCIAL_AREA, ((FollowedPerson)abs).getConntype().toString());
			else if(columns[i].equals(ConnectionTable.SELECTED))
				values.put(ConnectionTable.SELECTED, ((FollowedPerson)abs).isTurnedOn());
			else if(columns[i].equals(ConnectionTable.USERID))
				values.put(ConnectionTable.USERID, ((FollowedPerson)abs).getUserid());
		}
		return values;
	}

}
